/* 

Replication for "Hostile Sexism, Racial Resentment, and Political Mobilization"

Kevin Banda and Erin Cassese

Place the combomarginsplot.ado file in the same folder as the data and do file.
	It has been modified to allow marginal effects to be offset.

*/

use "anes_timeseries_2016_Stata13.dta", clear
sort V160001
merge V160001 using "anes_timeseries_2016_voteval.dta"
svyset [pweight=V160102], strata(V160201) psu(V160202)

* Did the respondent complete the pre and post waves of the survey?
rename V160502 bothwaves

* respondent gender
gen female=V161342
recode female -9=. 3=. 1=0 2=1
label define female 1 "Women" 0 "Men"
label values female female 

* respondent race
recode V161310x (1 = 1 "White") (2 = 2 "Black") (5 = 3 "Hispanic") (3 = 4 "Asian") ///
	(4 6 = 5 "Other") (. -9 = .), gen(race5)
	
* level of education
gen edu= V161270
recode edu -9=1 1/8=1 9=2 10=3 11=4 12=4 13=5 14/16=6 90=1 95=.
label define edu 1 "Less than HS" 2 "High school"  3 "Some college" 4 "2-year degree" 5 "4-year degree"  6 "Post-grade" 
label values edu edu

* income
rename V161361x income
replace income = . if income==-9 | income==-5

* age
recode V161267c -9=. -8=. 
gen age=2016-V161267c

* frequency of church attendance
gen cattend=0 if V161244==2
replace cattend=0 if V161245==5
replace cattend=1 if V161245==4
replace cattend=2 if V161245==3
replace cattend=3 if V161245==2
replace cattend=4 if V161245==1
replace cattend=5 if V161245a==2
label define cattendlab 0 "Never" 1 "A few times a year" 2 "Once or twice a month" ///
	3 "Almost every week" 4 "Weekly" 5 "More often than once a week"
label values cattend cattendlab

* PID
recode V161158x -8=. -9=.
rename V161158x pid7
recode pid7 (1/3=1 "Democrats")  (4=2 "Independents")  (5/7=3 "Republicans"), gen(pid3)

* ideology
rename V161126 ideo7
replace ideo7 = . if ideo7==-9 | ideo7==-8 | ideo7==99
recode ideo7 (1/3 = 1 "Liberal") (4 = 2 "Moderate") (5/7 = 3 "Conservative") (.=.), ///
	gen(ideo3)

* Interest in campaigns
recode V161004 (3 = 1 "Not much") (2 = 2 "Somewhat") (1 = 3 "Very much") (. = .), gen(interest)

* State of the national economy ("economic anxiety")
recode V161140x (1 = 5 "Much better") (2 = 4 "Somewhat better") (3 = 3 "About the same") ///
	(4 = 2 "Somewhat worse") (5 = 1 "Much worse") (-1 . = .), gen(econanx)
	
* Hostile sexism
* V161507 - Women often interpret innocent remarks as sexist
gen hostile1=V161507
recode hostile1 -9/-1=. 1=5 2=4 4=2 5=1 
* V161508 - Women fail to appreciate what men do for them
gen hostile2=V161508
recode hostile2 -9/-1=. 1=5 2=4 4=2 5=1 
*V161509 - Women try to seek power by gaining power over men
gen hostile3=V161509
recode hostile3 -9/-1=. 1=5 2=4 4=2 5=1 
* V161510 - Women put men on a tight leash 
gen hostile4=V161510 
recode hostile4 -9/-1=. 1=5 2=4 4=2 5=1

gen sexism = ((hostile1 + hostile2 + hostile3 + hostile4) - 4) / 16
alpha hostile1 hostile2 hostile3 hostile4

* Racial resentment
//V162212--slavery in past 
//V162211 --without special favors
// V162213--less than desere 
//V162214--blacks must try harder to get ahead

gen resent_workway =V162211
gen resent_slavery  =V162212
gen resent_deserve =V162213
gen resent_try =V162214
recode resent_workway 1=5 2=4 4=2 5=1 -9/-6=.
recode resent_slavery  -9/-6=.
recode resent_deserve  -9/-6=.
recode resent_try 1=5 2=4 4=2 5=1  -9/-6=.
gen resentment = ((resent_workway + resent_slavery + resent_deserve + resent_try) - 4) / 16
alpha resent_workway resent_slavery resent_deserve resent_try

* Validated turnout
rename vote2016 vvote16
* vote2016_clerical is the one we use because it's weighted based on clerical review of the voter file.

* Participation items

gen discuss=V162174a
recode discuss -9/-1=.
replace discuss=0 if V162174==2

* rallies
gen part1=V162011
recode part1  -9/-1=. 2=0
* sign 
gen part2=V162012
recode part2  -9/-1=. 2=0
* other party work
gen part3=V162013
recode part3  -9/-1=. 2=0
* $ to campaign or candidate
gen part4=V162014
recode part4  -9/-1=. 2=0
* $ to a party 
gen part5=V162016
recode part5  -9/-1=. 2=0
* $ to any other group 
gen part6=V162017
recode part6  -9/-1=. 2=0
* contact a Representative 
gen part7=V162019
recode part7  -9/-1=. 2=0
* Discussed politics with friends/family
recode V162174 (1 = 1) (2 = 0) (-6 -7 -9 . = .), gen(part8)

gen participation=part1+part2+part3+part4+part5+part6+part7+part8

* Rename participation variables
rename part1 rally
rename part2 sign
rename part3 workcp
rename part4 donatec
rename part5 donatep
rename part6 donateg
rename part7 contactrep
rename part8 talkpolitics

* State of residence, pre wave
rename V161010e state

* District indicator, pre wave
rename V161010f district

* Cook Political Report scores
gen cook = .
replace cook = 1 if state=="CA" | state=="CT" | state=="DE" | state=="DC" | state=="HI" ///
	| state=="IL" | state=="MD" | state=="MA" | state=="NJ" ///
	| state=="NY" | state=="OR" | state=="RI" | state=="VT" | state=="WA"
replace cook = 2 if state=="MN" | state=="NM" | state=="VA" | state=="ME"
replace cook = 3 if state=="CO" | state=="MI" | state=="NV" | state=="NH" | state=="PA" | state=="WI"
replace cook = 4 if state=="FL" | state=="NC"
replace cook = 5 if state=="AZ" | state=="GA" | state=="IA" | state=="OH" | state=="UT"
replace cook = 6 if state=="AK" | state=="IN" | state=="MO" | state=="SC" | state=="TX"
replace cook = 7 if state=="AL" | state=="AR" | state=="ID" | state=="KS" | state=="KY" ///
	| state=="LA" | state=="MS" | state=="MT" | state=="NE" | state=="ND" | state=="OK" ///
	| state=="SD" | state=="TN" | state=="WV" | state=="WY"
label define cooklab 1 "Solid D" 2 "Likely D" 3 "Lean D" 4 "Toss up" 5 "Lean R" ///
	6 "Likely R" 7 "Solid R"
label values cook cooklab

* Folded Cook scores for competition indicator
recode cook (1 7 = 1 "Solid") (2 6 = 2 "Likely") (3 5 = 3 "Lean") ///
	(4 = 4 "Toss up"), gen(competition)

* How many completed both waves?
ta bothwaves if race5==1

* Summary statistics
sum vote2016_clerical participation rally sign workcp donatec donatep donateg contactrep talkpolitics ///
	sexism resentment i.pid3 ideo7 female interest edu income cattend age econanx ///
	competition if race5==1 & bothwaves==1
	
* Histograms for key independent variables
histogram sexism if race5==1 & bothwaves==1, percent discrete xsize(8) ysize(4) xscale(range(-0.1 1.1)) ///
	xlabel(0(.1)1, labsize(medium) nogrid) xtitle("", size(medium)) ///
	yline(25, lc(white) lp(solid)) ytitle("Percentage of observations", size(medium)) ///
	ylabel(0(5)25, labsize(medium)) title("") subtitle(, size(medium)) ///
	by(pid3, title("Hostile sexism", size(medium)) row(1) note("")) name(hist1, replace)
	
histogram resentment if race5==1 & bothwaves==1, percent discrete xsize(8) ysize(4) xscale(range(-0.1 1.1)) ///
	xlabel(0(.1)1, labsize(medium) nogrid) xtitle("", size(medium)) ///
	yline(25, lc(white) lp(solid)) ytitle("Percentage of observations", size(medium)) ///
	ylabel(0(5)25, labsize(medium)) title("") subtitle(, size(medium)) ///
	by(pid3, title("Racial resentment", size(medium)) row(1) note("")) name(hist2, replace)

graph combine hist1 hist2, xsize(6.5) ysize(6.5) row(2)

sum sexism resentment if race5==1 & pid3==1 & bothwaves==1
sum sexism resentment if race5==1 & pid3==2 & bothwaves==1
sum sexism resentment if race5==1 & pid3==3 & bothwaves==1

**************
*** Models ***
**************

/*

Note: if you use Dropbox, you should pause syncing if you want to run all of the
"saving" options on the margins commands at the same time. Stata will tell you
that the file is read only, probably because Dropbox is trying to sync while the
command writes.

*/

* Validated turnout
logit vote2016_clerical i.pid3##c.sexism i.pid3##c.resentment ideo7 ///
	female interest edu income cattend age econanx competition [pw=V160102] if race5==1
estat ic

margins, dydx(sexism) at(pid3=(1 2 3)) predict(xb) level(90) saving(file1, replace)
margins, dydx(resentment) at(pid3=(1 2 3)) predict(xb) level(90) saving(file11, replace)

margins, at(sexism=(0(.1)1) pid3=(1))
marginsplot, recast(line) plotopts(lw(.8)) recastci(rarea) ciopts(color(black%50) lw(0)) ///
	xtitle("", size(medium)) yline(0 1, lc(white) lp(solid)) ///
	ytitle("", size(medium)) ylabel(0(.1)1, labsize(medium))  ///
	title("Validated turnout: Democrats", size(medium)) ///
	xsize(3) ysize(3) xlabel(, labsize(medium)) level(90) name(hs1, replace)

margins, at(resentment=(0(.1)1) pid3=(1))
marginsplot, recast(line) plotopts(lw(.8)) recastci(rarea) ciopts(color(black%50) lw(0)) ///
	xtitle("", size(medium)) yline(0 1, lc(white) lp(solid)) ///
	ytitle("", size(medium)) ylabel(0(.1)1, labsize(medium))  ///
	title("Validated turnout", size(medium)) ///
	xsize(3) ysize(3) xlabel(, labsize(medium)) level(90) name(rr1, replace)


* Non-turnout participation
reg participation i.pid3##c.sexism i.pid3##c.resentment ideo7 ///
	female interest edu income cattend age econanx competition [pw=V160102] if race5==1
estat ic

margins, dydx(sexism) at(pid3=(1 2 3)) predict(xb) level(90) saving(file2, replace)
margins, dydx(resentment) at(pid3=(1 2 3)) predict(xb) level(90) saving(file12, replace)


* Individual turnout items

* Rally
logit rally i.pid3##c.sexism i.pid3##c.resentment ideo7 ///
	female interest edu income cattend age econanx competition [pw=V160102] if race5==1
estat ic

margins, dydx(sexism) at(pid3=(1 2 3)) predict(xb) level(90) saving(file3, replace)
margins, dydx(resentment) at(pid3=(1 2 3)) predict(xb) level(90) saving(file13, replace)

margins, at(resentment=(0(.1)1) pid3=(3))
marginsplot, recast(line) plotopts(lw(.8) lp(dash)) recastci(rarea) ciopts(color(black%50) lw(0)) ///
	xtitle("", size(medium)) yline(0 1, lc(white) lp(solid)) ///
	ytitle("", size(medium)) ylabel(0(.1)1, labsize(medium))  ///
	title("Attending a rally", size(medium)) ///
	xsize(3) ysize(3) xlabel(, labsize(medium)) level(90) name(rr2, replace)

* Display a sign
logit sign i.pid3##c.sexism i.pid3##c.resentment ideo7 ///
	female interest edu income cattend age econanx competition [pw=V160102] if race5==1
estat ic
margins, dydx(sexism) at(pid3=(1 2 3)) predict(xb) level(90) saving(file4, replace)
margins, dydx(resentment) at(pid3=(1 2 3)) predict(xb) level(90) saving(file14, replace)

margins, at(resentment=(0(.1)1) pid3=(1 3))
marginsplot, recast(line) plotopts(lw(.8)) recastci(rarea) ciopts(color(black%50) lw(0)) ///
	xtitle("", size(medium)) yline(0 1, lc(white) lp(solid)) ///
	ytitle("", size(medium)) ylabel(0(.1)1, labsize(medium))  ///
	title("Displaying a sign", size(medium)) plot2opts(lw(.8) lp(dash) col(black)) ///
	xsize(3) ysize(3) xlabel(, labsize(medium)) level(90) name(rr3, replace) ///
	legend(off)

* Work for a campaign or party
logit workcp i.pid3##c.sexism i.pid3##c.resentment ideo7 ///
	female interest edu income cattend age econanx competition [pw=V160102] if race5==1
estat ic
margins, dydx(sexism) at(pid3=(1 2 3)) predict(xb) level(90) saving(file5, replace)
margins, dydx(resentment) at(pid3=(1 2 3)) predict(xb) level(90) saving(file15, replace)

margins, at(resentment=(0(.1)1) pid3=(1))
marginsplot, recast(line) plotopts(lw(.8)) recastci(rarea) ciopts(color(black%50) lw(0)) ///
	xtitle("", size(medium)) yline(0 1, lc(white) lp(solid)) ///
	ytitle("", size(medium)) ylabel(0(.1)1, labsize(medium))  ///
	title("Working for a candidate/party", size(medium)) ///
	xsize(3) ysize(3) xlabel(, labsize(medium)) level(90) name(rr4, replace)

* Donate to a campaign or candidate
logit donatec i.pid3##c.sexism i.pid3##c.resentment ideo7 ///
	female interest edu income cattend age econanx competition [pw=V160102] if race5==1
estat ic
margins, dydx(sexism) at(pid3=(1 2 3)) predict(xb) level(90) saving(file6, replace)
margins, dydx(resentment) at(pid3=(1 2 3)) predict(xb) level(90) saving(file16, replace)

margins, at(resentment=(0(.1)1) pid3=(1))
marginsplot, recast(line) plotopts(lw(.8)) recastci(rarea) ciopts(color(black%50) lw(0)) ///
	xtitle("", size(medium)) yline(0 1, lc(white) lp(solid)) ///
	ytitle("", size(medium)) ylabel(0(.1)1, labsize(medium))  ///
	title("Donating to a campaign or candidate", size(medium)) ///
	xsize(3) ysize(3) xlabel(, labsize(medium)) level(90) name(rr5, replace)

* Donate to a party
logit donatep i.pid3##c.sexism i.pid3##c.resentment ideo7 ///
	female interest edu income cattend age econanx competition [pw=V160102] if race5==1
estat ic
margins, dydx(sexism) at(pid3=(1 2 3)) predict(xb) level(90) saving(file7, replace)
margins, dydx(resentment) at(pid3=(1 2 3)) predict(xb) level(90) saving(file17, replace)

margins, at(resentment=(0(.1)1) pid3=(1))
marginsplot, recast(line) plotopts(lw(.8)) recastci(rarea) ciopts(color(black%50) lw(0)) ///
	xtitle("", size(medium)) yline(0 1, lc(white) lp(solid)) ///
	ytitle("", size(medium)) ylabel(0(.1)1, labsize(medium))  ///
	title("Donating to a party", size(medium)) ///
	xsize(3) ysize(3) xlabel(, labsize(medium)) level(90) name(rr6, replace)

* Donate to a group
logit donateg i.pid3##c.sexism i.pid3##c.resentment ideo7 ///
	female interest edu income cattend age econanx competition [pw=V160102] if race5==1
estat ic
margins, dydx(sexism) at(pid3=(1 2 3)) predict(xb) level(90) saving(file8, replace)
margins, dydx(resentment) at(pid3=(1 2 3)) predict(xb) level(90) saving(file18, replace)

margins, at(resentment=(0(.1)1) pid3=(1))
marginsplot, recast(line) plotopts(lw(.8)) recastci(rarea) ciopts(color(black%50) lw(0)) ///
	xtitle("", size(medium)) yline(0 1, lc(white) lp(solid)) ///
	ytitle("", size(medium)) ylabel(0(.1)1, labsize(medium))  ///
	title("Donating to a group", size(medium)) ///
	xsize(3) ysize(3) xlabel(, labsize(medium)) level(90) name(rr7, replace)

* Contacted a representative
logit contactrep i.pid3##c.sexism i.pid3##c.resentment ideo7 ///
	female interest edu income cattend age econanx competition [pw=V160102] if race5==1
estat ic
margins, dydx(sexism) at(pid3=(1 2 3)) predict(xb) level(90) saving(file9, replace)
margins, dydx(resentment) at(pid3=(1 2 3)) predict(xb) level(90) saving(file19, replace)

margins, at(sexism=(0(.1)1) pid3=(1))
marginsplot, recast(line) plotopts(lw(.8)) recastci(rarea) ciopts(color(black%50) lw(0)) ///
	xtitle("", size(medium)) yline(0 1, lc(white) lp(solid)) ///
	ytitle("", size(medium)) ylabel(0(.1)1, labsize(medium))  ///
	title("Contact representative: Democrats", size(medium)) ///
	xsize(3) ysize(3) xlabel(, labsize(medium)) level(90) name(hs2, replace)


* Talked about politics
logit talkpolitics i.pid3##c.sexism i.pid3##c.resentment ideo7 ///
	female interest edu income cattend age econanx competition [pw=V160102] if race5==1
estat ic
margins, dydx(sexism) at(pid3=(1 2 3)) predict(xb) level(90) saving(file10, replace)
margins, dydx(resentment) at(pid3=(1 2 3)) predict(xb) level(90) saving(file20, replace)

margins, at(sexism=(0(.1)1) pid3=(1))
marginsplot, recast(line) plotopts(lw(.8)) recastci(rarea) ciopts(color(black%50) lw(0)) ///
	xtitle("", size(medium)) yline(0 1, lc(white) lp(solid)) ///
	ytitle("", size(medium)) ylabel(0(.1)1, labsize(medium))  ///
	title("Talking politics: Democrats", size(medium)) ///
	xsize(3) ysize(3) xlabel(, labsize(medium)) level(90) name(hs3, replace)
	
margins, at(resentment=(0(.1)1) pid3=(1))
marginsplot, recast(line) plotopts(lw(.8)) recastci(rarea) ciopts(color(black%50) lw(0)) ///
	xtitle("", size(medium)) yline(0 1, lc(white) lp(solid)) ///
	ytitle("", size(medium)) ylabel(0(.1)1, labsize(medium))  ///
	title("Talking politics", size(medium)) ///
	xsize(3) ysize(3) xlabel(, labsize(medium)) level(90) name(rr8, replace)


* Marginal effects of hostile sexism on participation
combomarginsplot file10 file9 file8 file7 file6 file5 file4 file3 file2 file1, ///
	labels("Talk politics" "Contact representative" "Donate to group" "Donate to party" ///
	"Donate to candidate" "Work for candidate/party" "Display sign" "Attend rally" "Participation scale" ///
	"Validated turnout") ///
	recast(scatter) x(_filenumber) horizontal ytitle("") xline(0, lc(red)) ///
	xtitle("Marginal effect of hostile sexism") title("Hostile sexism") ///
	legend(pos(6) row(1)) xsize(8) ysize(6) xlabel(-8(2)12) ///
	plot1opts(mcolor(white) mlcolor(black)) ci1opts(msize(0)) ///
	plot2opts(mcolor(gs10) mlcolor(black)) ci2opts(msize(0) col(black)) ///
	plot3opts(mcolor(black) mlcolor(black)) ci3opts(msize(0) col(black)) ///
	offset(0.25) xline(-8 12, lc(white) lp(solid))

* Marginal effects of racial resentment on participation
combomarginsplot file20 file19 file18 file17 file16 file15 file14 file13 file12 file11, ///
	labels("Talk politics" "Contact representative" "Donate to group" "Donate to party" ///
	"Donate to candidate" "Work for candidate/party" "Display sign" "Attend rally" "Participation scale" ///
	"Validated turnout") ///
	recast(scatter) x(_filenumber) horizontal ytitle("") xline(0, lc(red)) ///
	xtitle("Marginal effect of racial resentment") title("Racial resentment") ///
	legend(pos(6) row(1)) xsize(8) ysize(6) xlabel(-6(2)4) ///
	plot1opts(mcolor(white) mlcolor(black)) ci1opts(msize(0)) ///
	plot2opts(mcolor(gs10) mlcolor(black)) ci2opts(msize(0) col(black)) ///
	plot3opts(mcolor(black) mlcolor(black)) ci3opts(msize(0) col(black)) ///
	offset(0.25) xline(-6 4, lc(white) lp(solid))
	
* Predicted probability of participation by hostile sexism
graph combine hs1 hs2 hs3, xsize(6.5) ysize(4) row(1) l1("Predicted probability") ///
	b1("Hostile sexism")

* Predicted probability of participation by racial resentment
graph combine rr1 rr2 rr3 rr4 rr5 rr6 rr7 rr8, xsize(16) ysize(8) row(2) l1("Predicted probability") ///
	b1("Racial resentment")





